<template>
  <div ref="container" class="container">
    <div> 
      <!--hot-->
      <div>
        <div class="hot-title">热门城市</div>
        <ul class="hot-list">
          <li class="hot-item" v-for="hotcity in hotCities" :key="hotcity.id" @click="changeCityName(hotcity.name)">
            {{ hotcity.name }}
          </li>
        </ul>
      </div>
      <!--sort-->
      <div>
        <div class="sort-title">字母排序</div>
        <ul class="sort-list">
          <li class="sort-item" v-for="(item, index) in cities" :key="index" @click="change(item.title)">
            {{ item.title }}
          </li>
        </ul>
      </div>
      <!--list-->
      <div class="list">
        <div :ref="item.title" v-for="(item, index) in cities" :key="index">
          <div class="list-title">{{ item.title }}</div>
          <ul class="list-message">
            <li
              class="list-item"
              v-for="(city, index) in item.lists"
              :key="index"
              @click="changeCityName(city)"
            >
              {{ city }}
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import {mapMutations} from 'vuex'
import BScroll from 'better-scroll'
export default {
  props: ["cities", "hotCities"],
  data() {
    return {
      scroll : {},
    }
  },
  mounted() {
    let container = this.$refs['container']
    this.scroll = new BScroll(container,{
      observeDOM:true,
      mouseWheel: true
      })
  },
  methods: {
    change(key){
      this.scroll.scrollToElement(this.$refs[key][0])
    },
    changeCityName(hotcityname){
      this.changeCity(hotcityname)
      this.$router.push("/")
    },
    ...mapMutations(['changeCity'])
  },
};
</script>
<style scoped>
.container{
  position: absolute;
  overflow: hidden;
  left: 0;
  right: 0;
  top: .88rem;
  bottom: 0;
  background-color: #f5f5f5;
}
.hot-title {
  font-size: 0.36rem;
  padding: 0.2rem;
}
.hot-list {
  background-color: #fff;
  overflow: hidden;
  position: relative;
}
.hot-list:before {
  content: " ";
  position: absolute;
  width: 33.33333%;
  left: 33.33333%;
  height: 100%;
  border-left: 0.02rem solid #ddd;
  border-right: 0.02rem solid #ddd;
}
.hot-item {
  position: relative;
  height: 1rem;
  font-size: 0.3rem;
  text-align: center;
  float: left;
  width: 33.3333%;
  line-height: 1rem;
  border-bottom: 0.02rem solid #ddd;
}
.sort-title {
  font-size: 0.36rem;
  padding: 0.2rem;
}
.sort-list {
  background-color: #fff;
  overflow: hidden;
  position: relative;
}
.sort-item {
  height: 1rem;
  font-size: 0.3rem;
  text-align: center;
  float: left;
  width: 16.667%;
  line-height: 1rem;
}
.list-title {
  font-size: 0.36rem;
  padding: 0.2rem;
}
.list-message:before {
  position: absolute;
  width: 25%;
  left: 25%;
  height: 100%;
  content: " ";
  border-left: 0.02rem solid #ddd;
  border-right: 0.02rem solid #ddd;
}
.list-message:after {
  position: absolute;
  width: 0%;
  left: 75%;
  height: 100%;
  content: " ";
  border-left: 0.02rem solid #ddd;
}
.list-item {
  position: relative;
  width: 25%;
  font-size: 0.28rem;
  text-align: center;
  line-height: 0.9rem;
  float: left;
  border-bottom: 0.02rem solid #ddd;
  /*溢出... */
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.list-message {
  background-color: white;
  overflow: hidden;
  position: relative;
}
</style>